package com.xyz.service;

import com.free.common.vo.ResultModel;
import com.free.exception.SystemException;
import com.xyz.blockqueue.QueueModel;
import com.xyz.dao.logic.CCustomersignLogic;
import com.xyz.domain.ext.EnumEventType;
import com.xyz.domain.table.CCustomer;
import com.xyz.domain.table.CCustomersign;
import com.xyz.eventoper.EventOperContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerSignService extends BaseService{

    @Autowired
    private CCustomersignLogic signLogic;

    @Autowired
    private EventOperContext context;

    public ResultModel sign() throws SystemException {
        CCustomer customer = getCurrentUser();
        CCustomersign signInfo = signLogic.sign(customer);
        if(signInfo == null){
            return ResultModel.failure();
        }
        afterSignSuccess(customer);
        return ResultModel.success();
    }

    /**
     * 注册成功后处理
     * @param customer
     */
    private void afterSignSuccess(CCustomer customer){
        QueueModel queueModel = new QueueModel();
        queueModel.setCustomerInfo(customer);
        queueModel.setEventType(EnumEventType.SignEvent);
        context.putQueue(queueModel);
    }
}
